/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { DefaultTaskSnapshot } from '../core/default-task-snapshot.js';
import { BasicFileSnapshot } from '../core/filesystem-snapshot.js';
import { Snapshot } from '../core/snapshot.js';

export class SnapshotComparatorService {
  private static _instance: SnapshotComparatorService | null = null;

  static getInstance(): SnapshotComparatorService {
    if (!SnapshotComparatorService._instance) {
      SnapshotComparatorService._instance = new SnapshotComparatorService();
    }
    return SnapshotComparatorService._instance;
  }

  static isDiff(oldSnapShot: Snapshot | undefined, newSnapShot: Snapshot | undefined): boolean {
    if (!oldSnapShot || !newSnapShot) {
      return true;
    }
    if (oldSnapShot instanceof BasicFileSnapshot && newSnapShot instanceof BasicFileSnapshot) {
      return !oldSnapShot.equals(newSnapShot);
    }

    if (oldSnapShot instanceof DefaultTaskSnapshot && newSnapShot instanceof DefaultTaskSnapshot) {
      return !oldSnapShot.compareTo(newSnapShot);
    }
    return true;
  }
}
